<template>
	<view class="container">
		<view class="header" >
			<view class="user_wrapper acea-row row-between">
				<image :src="merchantData.mer_avatar || '/static/images/f.png'" class="picture"></image>
				<view class="user_text">
					<view class="name acea-row">
						<text>{{merchantData.mer_name || ''}}</text>
						<!-- <image v-if="userInfo.member_icon" class="level_icon" :src="userInfo.member_icon" alt=""> -->
					</view>
					<view class="user_id">ID: {{merchantData.mer_id || ''}}</view>
				</view>
                <view class="">
                    <view v-if="userInfo.is_start" class="guanzhu" @click.stop="followAuthor()"><text class="iconfont icon-shangpinshuliang-jia"></text>关注</view>
                    <view  v-else class="yiguanzhu"><text class="iconfont"></text>已关注</view>
                </view>
			</view>
			<view class="plant_info acea-row">
				<view class="count_wrapper acea-row">
                    <navigator :url="userInfo.is_self ? '/pages/plantGrass/plant_user_fans/index' : ''" class="item" hover-class="none">
                    	<text>{{userInfo.fans}}</text>粉丝
                    </navigator>
					<navigator :url="userInfo.is_self ? '/pages/plantGrass/plant_user_attention/index' : ''" class="item" hover-class="none">
						<text>{{userInfo.focus}}</text>关注
					</navigator>
					<view class="item">
						<text>{{userInfo.start}}</text>喜欢
					</view>
					<view class="item">
						<text>{{userInfo.start}}</text>获赞
					</view>
				</view>
				<!-- <view v-if="!userInfo.is_self" @click.stop="followAuthor">
					<button v-if="!userInfo.is_start" class="follow_btn focus">
						<text class="iconfont icon-jiahao2"></text>关注
					</button>
					<button v-else class="follow_btn focused">已关注</button>
				</view> -->
				<!-- <view v-else>
					<navigator hover-class="none" url="/pages/plantGrass/plant_release/index" class="follow_btn focus">
						<text class="iconfont icon-fabu"></text>发布
					</navigator>
				</view> -->
			</view>
		</view>
        <view class="chatStore" @click="chat">联系店家 </view>
        <view class="main" style="border-radius: 16rpx 16rpx 0 0;color: #fff;">
        	<view class="tab_count" style="margin-bottom: 0;">
        		<text class="on" >我的店铺</text>
        	</view>
        	<view class="" style="margin: 20rpx 30rpx;">
                 <text class="iconfont icon-dingwei4"></text>
                 {{merchantData.address}}
        	</view>
            <swiper class="swiper" circular :indicator-dots="indicatorDots" :autoplay="autoplay"
                :interval="interval" :duration="duration" >
                <swiper-item v-for="(i,n) in merchantData.store_publicize_imgs" :key="n" style="width: 600rpx;">
                    <image :src="i" class="swiperImg"  mode="aspectFit"></image>
                </swiper-item>
            </swiper>
            <view class="tab_count" style="margin:40rpx 0;">
            	<text class="on" >简介</text>
            </view>
            <view class="" style="margin: 0 30rpx;font-size: 36rpx;line-height: 50rpx;">
                {{merchantData.store_notice_message}}
            </view>
        </view>
		<view class="main">
			<view v-if="userInfo.is_self" class="tab_count">
				<text @click.stop="changeTab(0)" :class="tab==0 ? 'on' : ''">作品{{allCount}}</text>
				<!-- <text @click.stop="changeTab(1)" :class="tab==1 ? 'on' : ''">赞过</text> -->
			</view>
			<view class="tab-cont">
				<view v-if="goods.length > 0" class="goods-wrap">
					<view class="goods">
						<WaterfallsFlow :wfList='goods' :isAuth="1" :uid="parseInt(uid)" :tab="tab"/>
					</view>
				</view>
				<view v-if="goods.length == 0 && !loading" class="empty">
					<image :src="`${domain}/static/images/no_thing.png`"></image>
					<text>暂无内容哦~</text>
				</view>
				<view class='loadingicon acea-row row-center-wrapper'>
					<text class='loading iconfont icon-jiazai' :hidden='loading==false'></text>
						<view class="end" :hidden="loading || goods.length == 0"><text :class="loaded ? 'loaded' : ''">{{loadTitle}}</text>
					</view>
				</view>
			</view>
		</view>
        <uni-popup ref="popup" type="center">
        	<view class="popContent">
                <image src="../../../static/images/close.png" @click="closePop" mode="widthFix"></image>
        	    <view class="name">店铺名:{{merchantData.mer_name}} </view>
                <view class="">店主名: {{merchantData.mer_name}}</view>
                <view class="">联系电话: {{merchantData.mer_name}}</view>
                <view class="">店铺地址: {{merchantData.mer_address}}</view>
        	</view>
        </uni-popup>
	</view>
</template>

<script>
	// +----------------------------------------------------------------------
	// | ju [星际明星娱乐-寻找好声音]
	// +----------------------------------------------------------------------
	// | Copyright (c) 2024 https://jufeiniu.com/ All rights reserved.
	// +----------------------------------------------------------------------
	// | Author: 巨说还行-乔欣弥弥-巨肥牛 <jufeiniu@163.com>
	// +----------------------------------------------------------------------
	// | Personal site: https://jufeiniu.com/
	// +----------------------------------------------------------------------
	import WaterfallsFlow from '@/components/plantWaterfallsFlow/WaterfallsFlow.vue'
	import { userInfoApi, followAuthorApi, userArticleLst, starArticleLst } from '@/api/community.js';
	import { mapGetters } from "vuex";
	import { toLogin } from '@/libs/login.js';
	import { HTTP_REQUEST_URL } from '@/config/app';
    import {
        getStoreDetail,
    } from '@/api/store.js';
	const app = getApp();
	export default {
		components: {
			WaterfallsFlow
		},
		data() {
			return {
                indicatorDots: false,
                
                circular: false,
                autoplay: true,
                interval: 3000,
                duration: 500,
				domain: HTTP_REQUEST_URL,
				goods: [], // 商铺演唱会音乐会
				loadTitle: '加载更多',
				loading: false,
				loaded: false,
				userInfo: {},
				where: {
					page: 1,
					limit: 30
				},
				tab: 0,
				uid: '',
                allCount:0,
                merchantData:{},
                merId:""
			}
		},
		created() {},
		computed: {
			...mapGetters(['isLogin','viewColor']),
		},
		watch: {},
		onLoad: function(options) {
			let that = this;
			that.merId = options.merId
			if (that.isLogin) {
                if(this.merId){
                        getStoreDetail(options.merId).then(res => {
                            that.merchantData = res.data
                            that.getAuthorInfo(res.data.uid);
                            that.getList(res.data.uid)
                            uni.hideLoading();
                        })
                }
              if(options.merData) this.merchantData = JSON.parse(options.merData)  
			
			} else {
				toLogin()
			}
		},
		
		onReady() {},
		mounted: function() {
        },
		methods: {
            chat(){
              this.$refs.popup.open()  
            },
            closePop(){
               this.$refs.popup.close()   
            },
			/*获取用户信息*/
			getAuthorInfo(id){
				let that = this;
					userInfoApi(id).then(res => {
						that.userInfo = res.data
					});
			},
			// 关注作者
			followAuthor: function() {
				if (this.isLogin === false) {
					toLogin()
				} else {
					let status = this.userInfo.is_start ? false : true
					followAuthorApi(this.userInfo.uid,{status: status}).then(res => {
						if (res.status === 200) {
							this.userInfo.is_start = this.userInfo.is_start ? false : true
						}
						this.$util.Tips({
							title: res.message
						});
					});
				}
			},
			changeTab(tab){
				this.tab = tab
				this.where.page = 1
				this.loaded = this.loading = false
				this.goods = []
				let uid = this.userInfo.is_self ? this.uid : this.userInfo.uid
				this.getList(uid)
			},
			// 获取用户的作品
			getList: function(uid) {
				let that = this;
				if (that.loaded || that.loading) return;
				that.loading = true;
				that.loadTitle = '';
				that.tab == 1 ? this.where.is_type = 1 : this.where.is_type = ''
				that.tab == 0 ?
				userArticleLst(uid,that.where).then(res => {
					let list = res.data.list;
					let goods = that.$util.SplitArray(list, that.goods);
					that.loaded = list.length < that.where.limit;
					that.loading = false;
					that.loadTitle = that.loaded ? '到底了' : '加载更多';
					that.$set(that, 'goods', goods);
					that.$set(that.where, 'page', that.where.page + 1);
                    that.allCount = res.data.count
				}).catch(err => {
					that.loading = false;
					uni.showToast({
						title: err,
						icon: 'none'
					})
				}) :
				starArticleLst(that.where).then(res => {
					that.loading = false;
					let list = res.data.list;
					let goods = that.$util.SplitArray(list, that.goods);
					that.loaded = list.length < that.where.limit;
					that.loading = false;
					that.loadTitle = that.loaded ? '到底了' : '加载更多';
					that.$set(that, 'goods', goods);
					that.$set(that.where, 'page', that.where.page + 1);
				}).catch(err => {
					that.loading = false;
					uni.showToast({
						title: err,
						icon: 'none'
					})
				})
			},
           
		},
		onReachBottom() {
			let uid = this.userInfo.is_self ? this.uid : this.userInfo.uid
			this.getList(uid);
		},
		onPullDownRefresh(){},
		// 滚动监听
		onPageScroll(e) {
			// 传入scrollTop值并触发所有easy-loadimage组件下的滚动监听事件
			uni.$emit('scroll');
		}
	}
</script>

<style lang="scss" scoped>
.container{
	
	min-height: 100vh;
}
.header{
	width: 750rpx;
	height: 400rpx;
	padding: 56rpx 30rpx 0;
	background-repeat: no-repeat;
	background-size: 100%;
	.user_wrapper{
		align-items: center;
		.image,uni-image,image{
			width: 140rpx;
			height: 140rpx;
			border-radius: 100%;
			border: 4rpx solid #ffffff;
		}
		.user_text{
			margin-left: 22rpx;
			color: #FFFFFF;
            flex: 1;
			.name{
				font-size: 34rpx;
				font-weight: bold;
				align-items: center;
			}
			.user_id{
				margin-top: 16rpx;
				font-size: 24rpx;
			}
			.level_icon{
				width: 34rpx;
				height: 32rpx;
				margin: 4rpx 0 0 6rpx;
				border: none;
			}
		}
	}
	.plant_info{
		margin-top: 60rpx;
		align-items: center;
		justify-content: space-between;
		.count_wrapper{
			color: #FFFFFF;
			font-size: 24rpx;
            flex:1;
			.item{
				text-align: center;
				
                flex:1;
				
				text{
					display: block;
					font-size: 44rpx;
                    font-weight: 600;
					margin-top: 10rpx;
				}
			}
		}
	}
	.follow_btn{
		color: #ffffff;
		font-size: 26rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		width: 146rpx;
		height: 62rpx;
		background-color: transparent;
		background-image: linear-gradient(270deg, var(--view-bntColor21) 0%, var(--view-bntColor22) 100%);
		border-radius: 33rpx;
		.iconfont{
			font-size: 16rpx;
			margin-right: 12rpx;
		}
		.icon-fabu{
			font-size: 24rpx;
		}
		&.focused{
			background: transparent;
			color: #FFFFFF;
			border: 1px solid #FFFFFF;
		}
	}
}
.main {
	background: #1B1B1B;
	padding: 30rpx 0;
	
	position: relative;
	margin-top: 40rpx;
	.tab_count{
		margin-bottom: 40rpx;
		
		text{
			font-size: 28rpx;
			
			margin: 0 30rpx;
			position: relative;
			padding-bottom: 10rpx;
			&.on{
				font-size: 32rpx;
				color: #fff;
				font-weight: bold;
				&::after{
					content: "";
					width: 40rpx;
					height: 5rpx;
					background: var(--view-theme);
					position: absolute;
					bottom: 0;
					left: 10rpx;
				}
			}
		}
	}
}
.goods {
	display: flex;
	flex-wrap: wrap;
	justify-content: space-between;
	width: 750rpx;
	padding: 0 20rpx;
}
.empty{
	margin: 130rpx 0 150rpx;
	text-align: center;
	image,uni-image{
		display: inline-block;
		width: 414rpx;
		height: 305rpx;
	}
	text{
		display: block;
		color: #999999;
		font-size: 26rpx;
	}
}
.end{
	margin-top: 50rpx 0;
	text-align: center;
	text{
		color: #999999;
		font-size: 22rpx;
		position: relative;
		&.loaded{
			&::before,&::after{
				content: "";
				display: inline-block;
				width: 22rpx;
				height: 1rpx;
				background: #999999;
				position: absolute;
				top: 18rpx;
				opacity: .5;
			}
			&::before{
				left: -30rpx;
			}
			&::after{
				right: -30rpx;
			}
		}
	}
}
.chatStore{
    width: 520rpx;
    height: 80rpx;
    font-size: 36rpx;
    background: #A187F9;
    border-radius: 32rpx;
    text-align: center;
    line-height: 80rpx;
    color: #fff;
    margin: 0 auto;
}
.popContent{
    width:560rpx;
    position: relative;
    image{
        position: absolute;
        width: 48rpx;
        right: -20rpx;
        top: -20rpx;
    }
        height: 324rpx;
        background-color: rgba(36,36,36,1);
        color: #fff;
        border-radius: 16rpx;
        padding: 60rpx;
        font-size: 28rpx;
        .name{
            font-weight: 500;
            
        }
        view{
            margin-bottom: 12rpx;
        }
}
.swiper{
    margin: 0 30rpx;
    height: 364rpx;
    .swiperImg{
        width: 100%;
        height: 100%;
        border-radius: 10rpx;
    }
}
.guanzhu{
            height: 50rpx;
    	    background: #A187F9;
    	    width: 120rpx;
    	    border-radius: 50rpx;
    	    text-align: center;
    	    line-height: 50rpx;
            font-size: 28rpx;
    	display: flex;
    	align-items: center;
        flex-direction: row;
    	justify-content: center;
    	color: #fff;
    	
    	.iconfont{
    		font-size: 20rpx;
    	}
    }
    .yiguanzhu{
        height: 50rpx;
        background: #A187F9;
        width: 120rpx;
        border-radius: 50rpx;
        text-align: center;
        color: #fff;
        line-height: 50rpx;
        font-size: 28rpx;
    }
</style>
